package org.springcloud.wisdom.amusement.login.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;
import org.springcloud.wisdom.amusement.entity.Student;
import org.springcloud.wisdom.amusement.login.entity.Team_Student;

import java.util.List;

@Mapper
public interface Team_StudentDao2 extends BaseMapper{

    //判断学生是否参加社团
    @Select("select * from team_student where sid=#{sid} and role != 3")
    public Team_Student selectTeamStudent(String sid);
    @Select("select name from team where id=#{teamid}")
    public String selectTeamName(Integer teamid);

    //查看社所有成员 teamid=1 唱歌社
    @Select("SELECT * FROM student WHERE sid IN " +
            "( " +
            " SELECT sid from team_student WHERE role != 3 and teamid = #{teamid} " +
            "and isdel = 0)")
    public List<Student> selectStudent(Integer teamid);

    @Select("SELECT * FROM student WHERE sid IN " +
            "( " +
            " SELECT sid from team_student WHERE role != 3 and teamid = #{teamid} " +
            ")")
    IPage<Student> selectStudentPage(Page<?> page,@Param("teamid") Integer teamid);

    //查看申请入队学生
    @Select("SELECT * FROM student WHERE sid IN " +
            "( " +
            " SELECT sid from team_student WHERE role = 3 and teamid = #{teamid} " +
            ")")
    public List<Student> selectAddStudent(Integer teamid);
    @Select("SELECT * FROM student WHERE sid IN " +
            "( " +
            " SELECT sid from team_student WHERE role = 3 and teamid = #{teamid} " +
            "and isdel != 1 " +
            ")")
    IPage<Student> selectAddStudentPage(Page<?> page,@Param("teamid") Integer teamid);

    //申请加入社团
    @Insert("insert into team_student(sid,teamid,role,reason) VALUES(#{sid},#{teamid},3,#{reason})")
    public int addPlayer(Team_Student teamStudent);

    //同意加入社团
    @Update("update team_student set role=0 where sid=#{sid} and teamid=#{teamid}")
    public int realAddPlayer(Team_Student teamStudent);

//    //同意加入社团
//    @Update("update team_student set role=0 where id=#{id}")
//    public int realAddPlayer(Integer id);
    //删除社员 删除报名失败也可以
    @Update("update team_student set isdel=1 where sid=#{sid} and teamid=#{teamid}")
    public int delPlayer(Team_Student teamStudent);

    //不同意加入社团
    @Delete("delete from team_student where sid=#{sid} and teamid=#{teamid}")
    public int deleteAddPlayer(String sid,Integer teamid);
}
